//
//  WBStatusModel.swift
//  微博(swift)
//
//  Created by 汤米 on 16/4/21.
//  Copyright © 2016年 汤米. All rights reserved.
//

import UIKit

class WBStatusModel: NSObject {

    /// 微博创建时间
    var created_at: String?
    /// 微博ID
    var id: Int64 = 0
    /// 微博信息内容
    var text: String?
    /// 微博来源
    var source: String?
    /// 用户信息
    var user: WBUserModel?
    /// 转发微博
    var retweeted_status: WBStatusModel?
    /// 配图数组
    var pic_urls: [WBPictureModel]?
    /// 转发数
    var reposts_count: Int = 0
    /// 评论数
    var comments_count	: Int = 0
    /// 表态数
    var attitudes_count: Int = 0



    
    // MARK: -  字典转模型
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    // MARK: -  重写 setValue 方法
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key == "user" {
            
            if let v = value as? [String: AnyObject]{
                
                user = WBUserModel(dict: v)
            }else {
                print("返回的不是一个字典")
            }
        }else if key == "retweeted_status" {
            
            if let v = value as? [String: AnyObject] {
                retweeted_status = WBStatusModel(dict: v)
            }
        }else if key == "pic_urls" {
            
            if let array = value as? [[String: AnyObject]] {
                
                //定义临时数组
                var tempArray: [WBPictureModel] = [WBPictureModel]()
                //遍历数组
                for dict in array {
                    
                    
                    tempArray.append(WBPictureModel(dict: dict))
                }
                
                pic_urls = tempArray
            }
            
        }else {
            
            super.setValue(value, forKey: key)
        }
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
}
